package com.ecarx.library_base.base_view;

import android.content.Context;
import android.util.AttributeSet;

import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatImageView;

import com.ecarx.library_base.base_util.DebounceClickListener;

/**
 * @author : kjn
 * @date : 19-5-7 上午10:18
 * Description : 触摸时显示50%的透明度
 */
public class ThemeImageView extends AppCompatImageView {


    public ThemeImageView(Context context) {
        super(context);
    }

    public ThemeImageView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);

    }


    public ThemeImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }


    @Override
    protected void dispatchSetPressed(boolean pressed) {
        if (this.isClickable()){
            if (pressed) {
                setAlpha(0.5f);
            } else {
                setAlpha(1f);
            }
        }
        super.dispatchSetPressed(pressed);
    }

    @Override
    public void setEnabled(boolean enabled) {
        super.setEnabled(enabled);
        setAlpha(enabled ? 1f : 0.5f);
    }

    @Override
    public void setOnClickListener(@Nullable OnClickListener l) {
        DebounceClickListener l1 = new DebounceClickListener(l);
        super.setOnClickListener(l1);
    }
}
